<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>添加菜单</title>
		<link rel="stylesheet" href="../../component/pear/css/pear.css" />
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form">
					<div class="layui-form-item">
						<label class="layui-form-label">菜单名</label>
						<div class="layui-input-block">
						<input type="text" name="title" lay-verify="required" placeholder="请输入菜单名" autocomplete="off" class="layui-input">
						</div>
					</div>		
					<div class="layui-form-item">
						<label class="layui-form-label">图标</label>
						<div class="layui-input-block">
						<input type="text" name="icon" lay-verify="required" placeholder="请输入图标" autocomplete="off" class="layui-input">
						</div>
					</div>				
					<div class="layui-form-item">
						<label class="layui-form-label">菜单类型</label>
						<div class="layui-input-block">
						<input type="radio" name="type" value="0" title="目录" lay-filter="type" checked>
						<input type="radio" name="type" value="1" title="页面" lay-filter="type">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">页面类型</label>
						<div class="layui-input-block">
						<input type="text" name="openType" id="openType" class="layui-input" disabled>
						</div>
					</div>	
					<div class="layui-form-item">
						<label class="layui-form-label">页面地址</label>
						<div class="layui-input-block">
						<input type="text" name="href" id="href" class="layui-input" disabled>
						</div>
					</div>	
					<div class="layui-form-item">
						<label class="layui-form-label">父ID</label>
						<div class="layui-input-block">
						<input type="text" name="parentId" id="parentId" lay-verify="required" class="layui-input" disabled>
						</div>
					</div>	
					<div class="layui-form-item">
						<label class="layui-form-label">菜单层级</label>
						<div class="layui-input-block">
						<input type="text" name="level" id="level" lay-verify="required" class="layui-input" disabled>
						</div>
					</div>	
					<div class="layui-form-item">
						<label class="layui-form-label">状态</label>
						<div class="layui-input-block">
						<input type="radio" name="status" value="1" title="可用" checked>
						<input type="radio" name="status" value="0" title="禁用">
						</div>
					</div>
					<div class="layui-form-item" style="text-align: right;">
						<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit lay-filter="add">添加</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
		</div>
		<script src="../../component/layui/layui.js"></script>
		<script src="../../component/pear/pear.js"></script>
		<script>
			layui.use(function(){

				let form = layui.form;
				let layer = layui.layer;
				let $ = layui.$;

				form.on('radio(type)', function(obj){
					if(obj.value==1){
						$('#openType').val("_iframe");
						$('#href').prop('disabled', false);
						$('#href').attr('lay-verify', 'required');
					}else{
						$('#openType').val("");
						$('#href').val("");
						$('#href').prop('disabled', true);
						$('#href').removeAttr('lay-verify');
					}
				});

				form.on('submit(add)', function(obj){
					$.ajax({
						type: 'post',
						url: 'http://127.0.0.1:8080/addMenu',
						data: JSON.stringify(obj.field),
						contentType: 'application/json',
						dataType: 'json',
						success: function(res){
							if(res.code==0){
								let index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							}else{
								layer.msg(res.msg);
							}
						}
					});
					return false;
				});

			});
		</script>
	</body>
</html>
